package com.eightworld3.supermarket.controller;

import com.eightworld3.supermarket.domain.CustomerTab;
import com.eightworld3.supermarket.service.CustomerTabService;
import com.eightworld3.supermarket.service.dto.CustomerTabDTO;
import com.eightworld3.supermarket.service.dto.add.CustomerTabAddDTO;
import com.eightworld3.supermarket.service.dto.result.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author EightWorld3
 */
@Tag(name = "CustomerTabController", description = "客户账单")
@RestController
@RequestMapping("/customerTab")
public class CustomerTabController {
    private final CustomerTabService customerTabService;

    /**
     * CustomerTabController构造方法
     * @param customerTabService 客户账单Service
     */
    public CustomerTabController(CustomerTabService customerTabService){
        this.customerTabService = customerTabService;
    }

    /**
     * 查询所有
     * @return 返回所有CustomerTab(客户账单)
     */
    @Operation(summary = "显示全部客户账单(CustomerTab)",description = "显示全部客户账单(CustomerTab)")
    @GetMapping("/allCustomerTab")
    public List<CustomerTab> getAll(){
        return customerTabService.selectAll();
    }

    /**
     * 根据tabId查询CustomerTab
     * @param tabId ID号
     * @return 返回tabId对应的CustomerTab对象(经ResponseResult包装类修饰)
     */
    @Operation(summary = "根据tabId查询客户账单(CustomerTab)",description = "根据tabId查询客户账单(CustomerTab)")
    @GetMapping("/getCustomerTabByTabId/{tabId}")
    public ResponseResult getCustomerTabById(@PathVariable("tabId") int tabId){
        return customerTabService.selectByTabId(tabId);
    }

    /**
     * 新增CustomerTab
     * @param customerTabAddDTO CustomerTab新增DTO对象
     * @return 返回当前当次新增状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "新增用户账单(CustomerTab)",description = "Test：数量(>0)、总价(>0)、登记日期(默认当前)、备注(varchar(120))")
    @PostMapping("/insertCustomerTab")
    public ResponseResult insertCustomerTab(@RequestBody CustomerTabAddDTO customerTabAddDTO){
        return customerTabService.addCustomerTab(customerTabAddDTO);
    }

    /**
     * 更新CustomerTab
     * @param customerTabDTO CustomerTab DTO对象
     * @return 返回当前当次更新状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "更新用户账单(CustomerTab)",description = "Test：数量(>0)、总价(>0)、登记日期(默认当前)、备注(varchar(120))")
    @PutMapping("/updateCustomerTab")
    public ResponseResult updateCustomerTab(@RequestBody CustomerTabDTO customerTabDTO){
        return customerTabService.updateCustomerTab(customerTabDTO);
    }

    /**
     * 根据tabId删除CustomerTab
     * @param tabId ID号
     * @return 返回当前当次删除状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "根据tabId删除用户账单(CustomerTab)",description = "根据tabId删除用户账单(CustomerTab)")
    @DeleteMapping("/deleteCustomerTabById/{tabId}")
    public ResponseResult deleteCustomerTabById(@PathVariable("tabId") int tabId){
        return customerTabService.deleteCustomerTabById(tabId);
    }
}
